package ligne2vie.topos.client.forms;

import ligne2vie.topos.shared.bo.TSummit;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * The class {@link SummitDeleteForm} provides a complete form in order to ask user confirmation to delete a summit. It
 * is directly embeddable into a widget and all its methods allows controlling it from anywhere.
 * 
 * @author thuguerre
 * @since 1.0.0
 */
public class SummitDeleteForm extends VerticalPanel {

	private Label summitName;
	private Button cancelButton;

	/**
	 * Default constructor.
	 * 
	 * @param okButton
	 *            The button which removes the summit. Up to the instantiating process to provide it due to very
	 *            specific action.
	 * @param cancelButton
	 *            The button which cancels the form and the action. Up to the instantiating process to provide it due to
	 *            very specific action.
	 */
	public SummitDeleteForm(final Button okButton, final Button cancelButton) {

		summitName = new Label();
		this.cancelButton = cancelButton;

		// --- Creating the final button panel

		HorizontalPanel buttonPanel = new HorizontalPanel();
		buttonPanel.add(cancelButton);
		buttonPanel.add(okButton);

		// --- Filling the panel

		this.add(new HTML("<p>Confirmez-vous la suppression du sommet :</p>"));
		this.add(summitName);
		this.setHorizontalAlignment(ALIGN_RIGHT);
		this.add(buttonPanel);

		this.focus();
	}

	/**
	 * The method {@link #focus()} set the focus on the first text box the user has to fill : the summit name.
	 */
	public void focus() {
		this.cancelButton.setFocus(true);
	}

	public void setName(String name) {
		this.summitName.setText(name + " ?");
	}

	/**
	 * Convenience method allowing filling current form with all information provided from received summit. By safety,
	 * all corresponding setters are called.
	 * 
	 * @param summit
	 *            Summit to fill the form with.
	 */
	public void setSummit(TSummit summit) {

		if (summit != null) {

			this.setName(summit.getName());
		}
	}

}
